package ro.myApp.security.client;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;

import ro.myApp.client.BaseView;
import ro.myApp.security.dto.UserActivationMessage;

@Name("activation")
@BypassInterceptors
@Scope(ScopeType.PAGE)
public class Activation  extends BaseView {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8104899758187101792L;

	private String code;
	
	private String username;
	
	@Logger
	private Log log;
	
	public void activate () {
		log.debug("Activate user with parameters: code = {0} and username = {1}", code, username);
		Object result = sendMessage (new UserActivationMessage(code, username));
		if (Boolean.TRUE.equals(result)){
			Identity.instance().getCredentials().setUsername(username);
			Identity.instance().login();
		}
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	
}
